<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function getRow(rowIndex) {
        let arr = [[1]]
        // if (rowIndex === 0) {
        //   return arr[rowIndex]
        // }
        for (let i = 1; i < rowIndex + 1; i++) {
          arr[i] = []
          for (let j = 0; j < i + 1; j++) {
            arr[i][j] = (arr[i - 1][j] || 0) + (arr[i - 1][j - 1] || 0)
          }
        }
        return arr[rowIndex]
      }

      // getRow(1)
      console.log(getRow(0))
      console.log(getRow(1))
      console.log(getRow(2))
      console.log(getRow(3))
    </script>
  </body>
</html>
